
<template>
<!-- 美团对账正常单    美团对账异常单 -->
    <div class="storeInfo">
        <div class="head">
            <el-form :model="form" class="headForm">
                
                <el-form-item style="width:230px">
                    <el-date-picker
                        v-model="form.date"
                        type="month"
                        value-format="yyyy-MM"
                        placeholder="选择月份">
                    </el-date-picker>
                </el-form-item>

                <el-form-item label="" style="width:105px">
                    <el-select v-model="form.type" placeholder="入库类型">
                        <el-option v-for="(item,a) in inType" :key="a" :label="item.status_cn" :value="item.status"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="" style="width:105px">
                <el-input v-model="form.item" placeholder="商品名称/条码"></el-input>
                </el-form-item>
                <el-form-item label="" style="width:105px">
                    <el-select v-model="form.provider_id" placeholder="供应商">
                        <el-option v-for="(item,a) in provider" :key="a" :label="item.provider_name" :value="item.provider_id"></el-option>
                    </el-select>
                </el-form-item>

               
            <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
            <el-button type="success"  @click="purchaseFn(2)">+采购赠送入库</el-button>
            <el-button type="warning"  @click="purchaseFn(1)">采购入库</el-button>
                
            </el-form>
            
        </div> 
        <!-- <p style="line-height:30px;padding-left:20px;margin-top:8px;color:#333" v-if="form.order_id == ''">最近{{total}}笔人工退款订单记录</p> -->
        <!-- table -->
        <div class="tabContainer_SI tabContainer">
            <el-table :data="tableData" stripe style="width: 100%;text-align:center" >
                <!-- 商品ID	商品名称	入库类型	采购数量	采购价格	合计	采购单	供应商	采购入库时间	操作人				 -->
                <el-table-column prop="item_id" label="商品ID" fixed ></el-table-column>
                <el-table-column prop="item_name" label="商品名称" width="300px"> </el-table-column>
                <el-table-column prop="type_cn" label="入库类型" ></el-table-column>
                <el-table-column prop="purchase_num" label="采购数量"></el-table-column>
                <el-table-column prop="provide_price" label="采购价格"></el-table-column>               
                <el-table-column prop="total_price" label="合计"></el-table-column>
                <el-table-column prop="purchase_image" label="采购单" >
                    <template slot-scope="scope">
                        <img :src="scope.row.purchase_image" alt="" style="width:60px;height:60px">
                    </template>
                </el-table-column>
                <el-table-column prop="provider_name" label="供应商"></el-table-column>
                <el-table-column prop="create_time" label="采购入库时间"></el-table-column>
                <el-table-column  label="操作人" prop="operate_name" ></el-table-column>

            </el-table>                       
        </div>
        <!-- 分页部分 -->
        <el-pagination
            background
            layout="total, prev, pager, next, jumper"
            @current-change="changePage"
            :page-size="size"
            :current-page.sync="pageNum"
            :hide-on-single-page=true
            :total="total">{{total}}
        </el-pagination>
       <!-- 库存借调 -->
        <el-dialog title="商品采购入库" :visible.sync="addalertShow" class="business">
            <el-form ref="form" :model="purchaseParam" label-width="120px">
                <el-form-item label="商品">
                    <searchGoods :input_url="searchgoodsurl" default_txt="" id="" v-on:getsearchItemGood="getgoods"></searchGoods>
                </el-form-item>
                <el-form-item label="供应商">
                    <el-input v-model="provider_name" type="text" disabled></el-input>
                </el-form-item>
                <div v-if="labelTxt=='入库数量'">
                    <el-form-item label="入库单价">
                        <el-input v-model="purchaseParam.provide_price" type="text" ></el-input>
                    </el-form-item>
                    <p class="info">小吃类商品请按照"份数"进行入库，售卖的最小单位为1份</p>    
                </div>
                
                <el-form-item :label="labelTxt">
                    <el-input v-model="purchaseParam.purchase_num" type="text" @blur="roundnum"></el-input>
                </el-form-item>
                <upload coverImg="" coverPath="" spantxt="入库单" v-on:throwFilePath="getImage" style="margin-bottom:15px"></upload>
                <el-form-item label="备注" resize="none">
                    <el-input v-model="purchaseParam.remarks" type="textarea" ></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="addalertShow = false">取 消</el-button>
                <el-button type="primary" @click="comfirm">确 定</el-button>
            </div>
        </el-dialog>

    </div>
</template>

<style lang="scss">
  .tabContainer_SI{
      .el-table{
          .cell{
              text-align: center;
          }
      }
  }
</style>
<style lang="less" scoped>
.info{
    margin-top: -20px;
    margin-bottom: 15px;
    margin-left: 120px;
    color: orange;
}
</style>
<script>
import Vue from 'vue';
import { abc } from "../../../../js/abc.js";
import {potUrl} from '../../../../js/config_url.js'; 
import searchGoods from '../../pop/goodslist.vue';
import upload from '../../pop/upload.vue';
let d = new Date();
let m = (d.getMonth()+1)>9?(d.getMonth()+1):'0'+(d.getMonth()+1)
let y = d.getFullYear()
let datenow = y+'-'+m;
console.log('ddd',y,m,datenow)
export default {
    components:{
        searchGoods,
        upload
    },
    data () {
    return {
        searchparams:'',
        tableData:[],
        total:50,
        size:20,
        form:{size:20,
            page:1,
            date:datenow
        },
        pageNum:1,
        inType:[
            {status:"",status_cn:"入库类型"},
            {status:"1",status_cn:"采购入库"},
            {status:"2",status_cn:"采购赠送"}

        ],
        provider:[],
        addalertShow:false,//弹框控制 
        purchaseParam:{},//弹框内得数据 
        searchgoodsurl:potUrl.itemSearch,
        provider_name:'',
        labelTxt:'dddd'
    }
  }, 
   mounted(){
      let that = this;
      that.getList();
      abc.get(that,potUrl.providersearch,{},(res)=>{
          that.provider = res.data
      })
      abc.limit(that,'storageIn')
  },
  watch:{
      expirationShow(){         
          this.expirarr = []
      }
  },
  methods:{
    search(){
        let that = this;
        //搜索有问题，搜索2019-03数据和2019-04数据是一样的；-error
        that.getList()
    },
    changePage(val){
        var that = this;
        that.pageNum = val;
        that.form.page = val;
        that.getList()
    },
    getList(){
        let that = this;
        abc.get(that,potUrl.purchaselist,that.form,(res)=>{
            that.liclicked = false;
            that.tableData=res.data.list;
            that.total = res.data.total;
        })//列表
    },
    purchaseFn(a){
        const that = this;
        that.purchaseParam.type = a
        that.addalertShow = true;
        a==1?that.labelTxt = '入库数量':that.labelTxt = '赠品数量';
        console.log(that.labelTxt)
    },
    comfirm(){
        //purchaseadd;
        const that = this;
        that.addalertShow = false;
        abc.post(that,potUrl.purchaseadd,that.purchaseParam,(res)=>{
            that.getList()
        })
    },
    getgoods(data){
        //获得模糊搜索得商品参数
        console.log(data);
        const that = this; 
        that.provider_name = data.provider_name;
        that.purchaseParam.provider_id = data.provider_id;
        that.purchaseParam.item_id = data.item_id;
    },
    getImage(data){
        //获得上传图片得地址
        const that = this;
        console.log(data)
        that.purchaseParam.image = data        
    },
    roundnum(){
        //商品数量必须为正整数
        const that = this;
        if(!abc.zzNum(that,that.purchaseParam.purchase_num )){
            that.purchaseParam.purchase_num = ""
        }
        
    }
  }
}
</script>
